<template>
  <el-dialog :visible.sync="visible" v-dialogDrag :title="title" :close-on-click-modal="false" class="tl-dialog" width="1200px" @open="open" @close="close">
    <el-form class="tl-form" ref="form" :model="model" :rules="rules" label-width="110px" :disabled="disableEditSubmit">
      <el-row>
        <el-col :span="12">
          <el-form-item label="所属公司编码" :rules="rules.validateRequire" prop="orgcode">
            <el-input v-model="model.orgcode" :readonly="true" class="is-disabled"></el-input>
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="所属部门" prop="deptcode" :required="true" :rules="rules.validateRequire">
            <tl-ref-dept v-model="model.deptcode" :initDisplayData.sync="model.dispdeptcode" dataType="code" :singleSelect="true" @confirm="onSelectDept" :externalQueryParam="{qry_enabled:1}"></tl-ref-dept>
          </el-form-item>
        </el-col>
      </el-row>
      <el-row>
        <el-col :span="12">
          <el-form-item label="资源名称" :rules="rules.validateRequire" prop="name">
            <el-input v-model="model.name"></el-input>
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="资源编码" :rules="rules.validateRequire" prop="code">
            <el-input v-model="model.code"></el-input>
          </el-form-item>
        </el-col>
      </el-row>
      <el-row>
        <el-col :span="12">
          <el-form-item label="单价" prop="price">
            <el-input-number v-model="model.price" controls-position="right" :step="1" :min="0" :precision="2" style="width:95%"></el-input-number>
            <span>元</span>
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="单位类型" prop="unittype">
            <el-select v-model="model.unittype" filterable clearable>
              <el-option v-for="item in codeModel.unittypeList" :key="item.code" :label="item.name" :value="item.code" />
            </el-select>
          </el-form-item>
        </el-col>
      </el-row>
      <el-row>
        <el-col :span="12">
          <el-form-item label="资源类型" prop="resourcetype">
            <el-select v-model="model.resourcetype" filterable clearable>
              <el-option v-for="item in codeModel.resourcetypeList" :key="item.code" :label="item.name" :value="item.code" />
            </el-select>
          </el-form-item>
        </el-col>
      </el-row>
      <el-row>
        <el-col :span="24">
          <el-form-item label="备注" prop="description">
            <el-input v-model="model.description" type="textarea" :rows="2"></el-input>
          </el-form-item>
        </el-col>
      </el-row>
    </el-form>
    <div slot="footer" class="dialog-footer">
      <el-button :type="disableEditSubmit === false ? 'text' : 'primary'" @click="doCancelEdit">取消</el-button>
      <el-button type="primary" @click="doSubmitEdit" :loading="saveLoading" v-if="disableEditSubmit === false">
                <svg-icon icon-class="save" />保存</el-button>
    </div>
  </el-dialog>
</template>

<script>
/** mixins */
import { mixin_edit } from "@tapui/mixins/mixin_edit"
/** 子组件 */
/** 工具类 */
import { putAction, getAction, postAction, deleteAction } from "@tapui/utils/http"
/** VUE配置 */
export default {
  mixins: [mixin_edit],
  components: {},
  data() {
    return {
      moduleTitle: "资源档案",
      urlPrefix: "/pm/resourceArchives/",
      url: {
        // 额外的url
        queryCodeList: "/pm/resourceArchives/dataCodeList",
        queryOrgByDeptId: "/pm/resourceArchives/queryOrgByDeptId"
      }
    }
  },
  methods: {
    loaded() {
      // 页面加载完毕执行
    },
    onSelectDept(selectedDepts) {
      const selectedDept = selectedDepts[0]
      const { id, code, fullname } = selectedDept
      this.$set(this.model, "deptcode", code)
      this.$set(this.model, "dispdeptcode", fullname)
      const param = {
        deptId: id
      }
      getAction(this.url.queryOrgByDeptId, param).then((res) => {
        if (res.success) {
          const { code: orgCode } = res.result
          this.$set(this.model, "orgcode", orgCode)
        } else {
          this.$tap.alert("已选部门关联公司信息错误，请联系系统管理员")
        }
      })
    }
  }
}
</script>
